package com.hmall.search.controller;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author Mingxi Guo
 * @Date 2022年7月16日21:14:07
 * @Email guomingxi2018@163.com
 */

@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    private SearchService searchService;

    /**
     * 搜索框自动补全
     *
     * @return
     */
    @GetMapping("/suggestion")
    public List<String> suggest(String key) {

        return searchService.suggest(key);
    }

    /**
     * 输入框搜索功能
     *
     * @return
     */
    @PostMapping("/list")
    public PageDTO<ItemDoc> list(@RequestBody RequestParams requestParams) {
        return searchService.list(requestParams);
    }

    /**
     * 过滤项聚合功能
     *
     * @param requestParams
     * @return
     */
    @PostMapping("filters")
    public Map<String, List<String>> filters(@RequestBody RequestParams requestParams) {

        return searchService.aggregation(requestParams);
    }
}
